<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8"/>
    <title>找回密码</title>
    <link rel="stylesheet" href="/css/abchat.css"/>
    <link rel="stylesheet" href="/css/bootstrap.css"/>
    <link rel="icon" type="image/x-icon" href="/image/favicon.ico"/>
</head>
<body class="forget">
<div class="container">
    <form class="form-signin" onsubmit="return false;" >
        <h3 class="form-signin-heading">ABChat | 找回密码</h3>
        <div class="form-label">
            <label for="email">邮箱地址</label>
            <label class="form-message hidden">邮箱不存在</label>
        </div>
        <input type="email" id="email" class="form-control" required="true" autofocus="true"/>
        <div class="form-label">
            <button class="btn btn-lg btn-primary btn-block submit-btn"  type="submit">找回密码</button>
        </div>

    </form>
</div>
<script th:src="@{/js/jquery-3.2.1.js}"></script>
<script th:src="@{/js/bootstrap.js}"></script>
<script th:src="@{/js/http.js}"></script>
<script th:src="@{/js/abchat.js}"></script>
<script th:inline="javascript">
    $('#email').on("keyup",function () {
        if ( $(this).val().trim() != ""){
            errorDisplay( $(this));
        }
    });
    $('#email').on("change",function () {
        // 进行用户名是否被注册检测
        var email = $(this).val().trim();
        if (email == ""){
            checkForm($(this),"不能为空");
            return false;
        }
        if (!regEmail.test(email)){
            checkForm($(this),"格式错误");
            return false;
        }

        httpGet(httpURL + "/auth/check/email?email="+email,function (data) {
            if (data.code == 200){
                var $parent = $('#email').parent();
                var $message = $parent.find('.form-message');
                $message.text("邮箱地址未注册");
                $message.removeClass("hidden");
                setInputColor($parent,true);
            }
        });


    });
    $('.submit-btn').on("click",function () {
        var text = "不能为空";
        var email = $('#email').val().trim();
        if (email == ""){
            checkForm($('#email'),text);
            return false;
        }
        var data = {
            "email" : email
        };
        httpPost(httpURL+"/auth/forget",data,function (data) {
            if (data.code != 200){
                var $parent = $('#email').parent();
                var $message = $parent.find('.form-message');
                $message.text(data.payload);
                $message.removeClass("hidden");
                setInputColor($parent,true);
            }else {
                window.location.href = "/page/message/forget";
            }
        })

    });
</script>
</body>
</html>